#include <limits.h>  // INT_MIN,INT_MAX
#include <math.h>    // abs,pow

#include <iostream>       // cout,cin
#include <string>         // string
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set

using namespace std;

class Solution {
   public:
    int singleNumber(vector<int>& nums) {
        int one = 0, two = 0;
        for (int num : nums) {
            one = one ^ num & ~two;
            two = two ^ num & ~one;
        }
        return one;
    }
};